<?php



namespace App\Http\Controllers;



use App\Http\Service\Impl\IndexImpl;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\DB;

use App\Http\Service;



/**

 * Class IndexController

 * @package App\Http\Controllers

 * 权限控制器

 */

class IndexController extends Controller
{

    private $Indexservice;
    public function __construct()
    {

        $this->Indexservice = new IndexImpl();
    }



    /**
     * 后台首页
     * http://localhost/crm/public/view_girdindex
     */
    public function view_girdindex()
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        return view("Index.girdindex", ['ip' => $ip]);
    }


    /**
     * 后台管理员列表
     */
    public function view_managerlist()
    {
        return view("Index.managerlist")->with("roles", $this->Indexservice->rolelist());
    }


    /**

     * 角色列表

     */

    public function view_rolelist()
    {

        return view("Index.rolelist");
    }



    /**

     * @param 管理员详情

     */

    public function view_editoradmin(Request $request)
    {

        $data = $this->Indexservice->editor_detail($request);

        return view("Index.editoradmin", [

            "roles" => $data['rolelist'],

            "have" => $data['have'],

            "info" => $data['info'][0]

        ]);
    }



    /**

     * 新增角色

     */

    public function view_roleadd()
    {

        return view("Index.roleadd");
    }



    /**

     * 新增管理员

     */

    public function view_adminadd(Request $request)
    {

        $data = $this->Indexservice->editor_detail($request);

        return view("Index.adminadd", ["roles" => $data['rolelist']]);
    }



    /**

     * 角色数据接口

     */

    public function IRoleList(Request $request)
    {

        return $this->Indexservice->rolelist();
    }



    /**

     * 按钮权限列表

     */

    public function rolebtnlist()
    {

        return $this->Indexservice->rolebtnlist();
    }



    /**

     * 后台管理员列表数据

     */

    public function mldata(Request $request)
    {

        return $this->Indexservice->userlist($request);
    }



    /**

     * @param Request $request

     * @return false|string 更新角色和用户

     */

    public function updaterole(Request $request)
    {

        return $this->Indexservice->updaterole($request);
    }



    /**

     * @param Request $request

     * @return mixed

     * 获取相应角色树形菜单

     */

    public function getauth(Request $request)
    {

        return $this->Indexservice->getauth($request);
    }



    /**

     * 获取角色的按钮权限

     */

    public function getrolebtnlist(Request $request)
    {

        return $this->Indexservice->getrolebtnlist($request);
    }



    /**

     * @param Request $request 新增角色

     */

    public function addrole(Request $request)
    {

        return $this->Indexservice->addrole($request);
    }



    public function addroleauth(Request $request)
    {

        return $this->Indexservice->addroleauth($request);
    }



    /**

     * @param Request $request

     * 新增管理员

     */

    public function addmanager(Request $request)
    {

        return $this->Indexservice->addmanager($request);
    }



    /**

     * @param Request $request

     * 删除管理员

     */

    public function deletemanager(Request $request)
    {

        return $this->Indexservice->deletemanager($request);
    }



    /**

     * 树菜单接口

     */

    public function gettree(Request $request)
    {

        return $this->Indexservice->gettree($request);
    }
}
